package server.game.world.map;

import server.game.Constants;
import server.game.world.map.properties.TileProperties;

public class Tile {

	private Region region;
	private int regionX, regionY, worldX, worldY;
	private TileProperties properties;
	
	public Tile(Region region, int regionX, int regionY) {
		new Tile(region, regionX, regionY, 0);
	}
	
	public Tile(Region region, int regionX, int regionY, int tileID) {
		this.region = region;
		this.regionX = regionX;
		this.regionY = regionY;
		worldX = Constants.REGION_SIZE * region.getX() + regionX;
		worldY = Constants.REGION_SIZE * region.getY() + regionY;
		properties = new TileProperties(tileID, false);
	}
	
	public double getDistance(Tile other) {
		if(other.getRegion() == getRegion()) {
			return Math.sqrt((other.getRegionX()-getRegionX())*(other.getRegionX()-getRegionX()) + (other.getRegionY()-getRegionY())*(other.getRegionY()-getRegionY()));
		} else {
			return Math.sqrt((other.getWorldX()-getWorldX())*(other.getWorldX()-getWorldX()) + (other.getWorldY()-getWorldY())*(other.getWorldY()-getWorldY()));
		}
	}
	
	public Region getRegion() {
		return region;
	}

	public int getRegionX() {
		return regionX;
	}

	public int getRegionY() {
		return regionY;
	}

	public int getWorldX() {
		return worldX;
	}

	public int getWorldY() {
		return worldY;
	}
	
	public TileProperties getProperties() {
		return properties;
	}
	
}
